home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / n_shell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  1.3 KB  |  68 lines

  1. /*
  2.  * Spawn a "native" shell.  Native means the shell found in the SHELL
  3.  * environmental variable.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <signal.h>
  8. #include <curses.h>
  9. #include "config.h"
  10.  
  11. void
  12. n_shell()
  13. {
  14.     WINDOW *sh_win, *newwin();
  15.     SIG_TYPE (*istat)(), (*qstat)();
  16.     int sig_status, spid, w;
  17.     char *shell, *shellpath, *getenv(), *strrchr();
  18.     unsigned int sleep();
  19.     void _exit();
  20.                     /* a full window */
  21.     sh_win = newwin(LINES, COLS, 0, 0);
  22.  
  23.     touchwin(sh_win);
  24.     waddstr(sh_win, "Pcomm <=> Unix gateway, use ^D or 'exit' to return\n");
  25.     wrefresh(sh_win);
  26.                     /* out of curses mode */
  27.     resetterm();
  28.  
  29.     shellpath = getenv("SHELL");
  30.     if (shellpath == NULL || *shellpath == '\0')
  31.         shellpath = "/bin/sh";
  32.  
  33.     if (shell = strrchr(shellpath, '/'))
  34.         shell++;
  35.     else {
  36.         shellpath = "/bin/sh";
  37.         shell = "sh";
  38.     }
  39.  
  40.     if (!(spid = fork())) {
  41.         signal(SIGINT, SIG_DFL);
  42.         signal(SIGQUIT, SIG_DFL);
  43. #ifdef SETUGID
  44.         setgid(getgid());
  45.         setuid(getuid());
  46. #endif /* SETUGID */
  47.         execl(shellpath, shell, "-i", (char *) 0);
  48.         _exit(1);
  49.     }
  50.     istat = signal(SIGINT, SIG_IGN);
  51.     qstat = signal(SIGQUIT, SIG_IGN);
  52.  
  53.     while ((w = wait(&sig_status)) != spid && w != -1)
  54.         ;
  55.  
  56.     signal(SIGINT, istat);
  57.     signal(SIGQUIT, qstat);
  58.                     /* back to curses mode */
  59.     sleep(1);
  60.     fixterm();
  61.  
  62.     clearok(curscr, TRUE);
  63.     werase(sh_win);
  64.     wrefresh(sh_win);
  65.     delwin(sh_win);
  66.     return;
  67. }
  68.